﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Uber.Core.Model
{
    public class Entity
    {
        public long Id { get; set; }
    }

    public class Product : Entity
    {
        public string Code { get; set; }
        public string Name { get; set; }
        public string Title { get; set; }
        public long? LatestProductVersionId { get; set; }
        public virtual ICollection<ProductVersion> ProductVersions { get; set; } 
    }

    public class ProductVersion : Entity
    {
        public long ProductId { get; set; }
        public virtual Product Product { get; set; }
        public string Description { get; set; }
        public bool IsActive { get; set; }
        public string FileName { get; set; }
        public DateTime DateCreated { get; set; }
        public string VersionNumber { get; set; }
    }

    public class Purchase : Entity
    {
        public long ProductVersionId { get; set; }
        public virtual ProductVersion ProductVersion { get; set; }

        public string PaypalTransactionId { get; set; }
        public int Quantity { get; set; }
        public decimal AmountPayed { get; set; }

        public long UserId { get; set; }
        public virtual Account User { get; set; }

        public string Custom { get; set; }
        public DateTime DateCreated { get; set; }
        public bool IsProcessed { get; set; }

        public virtual ICollection<License> Licenses { get; set; }
    }

    public class License : Entity
    {
        public long ProductVersionId { get; set; }
        public virtual ProductVersion ProductVersion { get; set; }

        public long UserId { get; set; }
        public virtual Account User { get; set; }

        public long PurchaseId { get; set; }
        public virtual Purchase Purchase { get; set; }

        public string Code { get; set; }
        public string Key { get; set; }

        public DateTime DateOfIssue { get; set; }
    }

    public class Account : Entity
    {
        public string Oid { get; set; }
        public string Email { get; set; }
        public string Aemail { get; set; }
        public string DisplayName { get; set; }
        public bool IsAweOid { get; set; }
        public DateTime CreationDate { get; set; }
        public bool MailOnAnswer { get; set; }
        public bool MailOnComment { get; set; }

        [NotMapped]
        public string Mail { get { return Aemail ?? Email; } }

        [NotMapped]
        public bool HasMail { get { return Mail != null; } }
    }

    public class AweOid : Entity
    {
        public string Email { get; set; }
        public string Password { get; set; }
        public long Code { get; set; }
    }

    public class Post : Entity
    {
        public string Title { get; set; }
        public string Body { get; set; }
        public DateTime CreationDate { get; set; }
        
        public long? ParentId { get; set; }
        public virtual Post Parent { get; set; }

        public virtual ICollection<Post> Posts { get; set; }

        public long OwnerId { get; set; }
        public virtual Account Owner { get; set; }
        public long? AcceptedAnswerId { get; set; }
        public virtual ICollection<Comment> Comments { get; set; }
    }

    public class Comment : Entity
    {
        public long PostId { get; set; }
        public virtual Post Post { get; set; }
        public string Body { get; set; }
        public long OwnerId { get; set; }
        public virtual Account Owner { get; set; }
        public DateTime CreationDate { get; set; }
    }

    public class Notification : Entity
    {
        public long AccountId { get; set; }
        public virtual Account Account { get; set; }
        public DateTime Date { get; set; }
        public long PostId { get; set; }
        public virtual Post Post { get; set; }
        public int NType { get; set; }
        public bool IsRead { get; set; }
        public long CauseId { get; set; }
        public bool SendEmail { get; set; }
        public string Email { get; set; }
    }
}